#!/usr/bin/env python
# encoding: utf-8
"""
forms.py

Created by reedhong on 2011-10-18.
Copyright (c) 2011 __MyCompanyName__. All rights reserved.
"""

#coding=utf-8

from django import forms
from question.models import Category
from question.models import Question

    
class QuestionForm(forms.Form):
    photo  = forms.FileField(label=u"照片", required=False)
    category = forms.ModelChoiceField(label=u"分类", queryset=Category.objects.all())
    content = forms.CharField(label=u"提问", widget=forms.Textarea)
    
    warn = ""
        
    def __init__(self, request=None, *args, **kwargs):
        super(QuestionForm, self).__init__(*args, **kwargs)
        
    def save(self, user, image):
        content = self.cleaned_data['content']
        category = self.cleaned_data['category']
        question = Question(user=user, image=image, content=content, category=category)
        question.save()        
        return question